package com.yehui.guava.concurrent;

import com.google.common.util.concurrent.RateLimiter;

/**
 * @author 业徽
 * @date 2021/7/22
 */
public class RateLimiterDemo {

    public static void main(String[] args) throws InterruptedException {
        final RateLimiter rateLimiter = RateLimiter.create(5);

        System.out.println(rateLimiter.acquire(4));
        // 这里能预借，所以1s左右就能获取到，后面的就被阻塞了
        System.out.println(rateLimiter.acquire(50));
        System.out.println(rateLimiter.acquire(50));
    }

}
